package com.shanghaionstar.carmanage;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.onstar.cn.common.util.BitmapUtil;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.onstar.cn.map.util.ToastUtil;
import com.onstar.cn.ripple.view.RippleCustomBtn;
import com.onstar.cn.vehicle.entity.DiagnosticElement;
import com.onstar.cn.vehicle.response.DiagnosticResponse;
import com.onstar.cn.weight.CustomImageView;
import com.onstar.cn.weight.ProgressLayout;
import com.shanghaionstar.R;
import com.shanghaionstar.carmanage.chargpile.ChargingPileListFragment;
import com.shanghaionstar.carmanage.iview.ICarStatusView;
import com.shanghaionstar.carmanage.presenter.CarStatusPresenter;
import com.shanghaionstar.home.model.DiagnosticResponses;
import com.shanghaionstar.sqlite.DatabaseOvdHistory;
import com.shanghaionstar.utils.AlertDialogUtil;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.FinalConstants;
import com.shanghaionstar.utils.TextViewUtil;
import com.shanghaionstar.weight.DialPlateView;
import com.shanghaionstar.weight.PsiView;
import com.shanghaionstar.weight.SuperSwipeRefreshLayout;

import java.util.List;

/**
 * Created by Yonglang Hong on 2016/8/23.
 */
public class VechileStatusFragment extends BaseFragment implements ICarStatusView {

    /**** 刷新layout***/
    @FindViewById
    private SuperSwipeRefreshLayout refreshLayout;
    /******** 刷新动画******/
    private AnimationDrawable animationDrawable;
    /*** 混合动力phev数据显示**/
    //PHEV车辆视图，搜索充电桩按钮
    private Button btn_searchChargingPile;
    //电池电量、综合里程、电动里程、机油寿命、燃油余量、总里程、充电状态提示、充电百分比
    private TextView tv_battery, tv_synthesizeMiles, tv_elecMiles, tv_oilLife, tv_sumMiles, tv_chargingStatus, tv_chargePercent;
    //正在充电动画
    private CustomImageView img_chargingSatus;
    //燃油余量
    private CarManageFuelMeterView fuelView;
    /*** 燃油车辆数据显示**/
    //表盘
    private DialPlateView dialView_fuel;
    //机油寿命、总里程、燃油余量
    private TextView tv_fuelCarOilLife, tv_fuelCarSumMiles, tv_remainFuelPer;
    /**** 胎压监控**/
    @FindViewById
    private RelativeLayout rl_psi;
    //前、后胎压参考值;前、后、左、右胎压值
    @FindViewById
    private TextView tv_psiFront, tv_psiRear, tv_lfPsi, tv_lrPsi, tv_rfPsi, tv_rrPsi;
    //车、前、后、左、右胎压状态图
    @FindViewById
    private ImageView img_tire_car, img_lfPsi, img_lrPsi, img_rfPsi, img_rrPsi;
    //维修保养建议
    @FindViewById
    private RippleCustomBtn rbtn_checkAdvice;
    //网络加载进度
    @FindViewById
    private ProgressLayout pl_loading;
    //页面数据
    private DatabaseOvdHistory ovdHistory;
    //维修保养建议参数
    private Bundle checkMaintainBundle = new Bundle();

    private CarStatusPresenter statusPresenter;

    @FindViewById
    private PsiView psiView;

    @Override
    public int getLayoutId() {
        return R.layout.car_manage_fragment_car_status;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
    }

    private void init() {
        getDataFromDB();
        setUpRefreshLayout();
        showViewsByCarType();
        setListeners();
    }

    private void setListeners() {
        rbtn_checkAdvice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoCheckMaintain();
            }
        });
        if (btn_searchChargingPile != null)
            btn_searchChargingPile.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    gotoChargingPile();
                }
            });
    }

    /**
     * 根据车辆类型显示车况内容
     */
    private void showViewsByCarType() {
        if (ApplicationUtil.getInstance().isPhev())  //显示phev
            showAndInitPhevViews();
        else                                       //显示非phev
            showAndInitFuelViews();
        if (!isTireSupport())                      //是否支持胎压显示
            rl_psi.setVisibility(View.GONE);
        else
            setUpPsiViews();
    }

    private void setUpPsiViews() {
        img_tire_car.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire));
    }

    private boolean isTireSupport() {
        boolean support = false;
        String[] diagnostics = ApplicationUtil.getInstance().getSupportedDiagnostic();
        if (diagnostics != null && diagnostics.length > 0) {
            for (String diagnostic : diagnostics) {
                if (Constants.TIRE_PRESSURE.equals(diagnostic)) {
                    support = true;
                    break;
                }
            }
        }
        return support;
    }

    private void showAndInitPhevViews() {
        ViewStub phevStub = (ViewStub) getContentView().findViewById(R.id.vs_phev);
        phevStub.inflate();
        tv_battery = (TextView) getContentView().findViewById(R.id.tv_battery);
        tv_oilLife = (TextView) getContentView().findViewById(R.id.tv_oilLife);
        tv_sumMiles = (TextView) getContentView().findViewById(R.id.tv_sumMiles);
        tv_elecMiles = (TextView) getContentView().findViewById(R.id.tv_elecMiles);
        tv_chargePercent = (TextView) getContentView().findViewById(R.id.tv_chargePercent);
        tv_chargingStatus = (TextView) getContentView().findViewById(R.id.tv_chargingStatus);
        tv_synthesizeMiles = (TextView) getContentView().findViewById(R.id.tv_synthesizeMiles);
        btn_searchChargingPile = (Button) getContentView().findViewById(R.id.btn_searchChargingPile);
        fuelView = (CarManageFuelMeterView) getContentView().findViewById(R.id.fuelView);
        img_chargingSatus = (CustomImageView) getContentView().findViewById(R.id.img_chargingSatus);
    }

    private void showAndInitFuelViews() {
        ViewStub fuelStub = (ViewStub) getContentView().findViewById(R.id.vs_fuel);
        fuelStub.inflate();
        dialView_fuel = (DialPlateView) getContentView().findViewById(R.id.dialView_fuel);
        tv_fuelCarOilLife = (TextView) getContentView().findViewById(R.id.tv_fuelCarOilLife);
        tv_fuelCarSumMiles = (TextView) getContentView().findViewById(R.id.tv_fuelCarSumMiles);
        tv_remainFuelPer = (TextView) getContentView().findViewById(R.id.tv_remainFuelPer);
        tv_remainFuelPer.setText(String.format(getResources().getString(R.string.remain_fuel), "---"));
    }

    /**
     * 从数据库获取车况
     */
    private void getDataFromDB() {
        String vin = null;
        if (!CommonUtil.isNull(ApplicationUtil.getInstance().getVin())) {
            vin = ApplicationUtil.getInstance().getCurrentVehicle().getVin();
        }
        refreshLayout.setRefreshing(true);
        getPresenter().getCarStatusFromDb(vin);
    }

    private void setUpRefreshLayout() {
        refreshLayout.setTargetScrollWithLayout(true);
        View head = LayoutInflater.from(baseActivity).inflate(R.layout.head_carstatus_loading, refreshLayout, false);
        refreshLayout.setHeaderView(head);
        ImageView img_loading = (ImageView) head.findViewById(R.id.img_loading);
        animationDrawable = (AnimationDrawable) img_loading.getDrawable();
        refreshLayout.setOnPullRefreshListener(refreshLayout.new OnPullRefreshListenerAdapter() {
            @Override
            public void onRefresh() {
                animationDrawable.start();
                refreshVechileStatus();
            }
        });
    }

    /**
     * 下发刷新指令
     */
    private void refreshVechileStatus() {
        if (validateDataRefresh())
            getPresenter().refreshVechileData();
    }

    /**
     * 取消加载状态的view
     */
    private void dismissLoadingViews() {
        pl_loading.setVisibility(View.GONE);
        refreshLayout.setRefreshing(false);
        animationDrawable.stop();
    }

    /**
     * 校验当前指令是否可执行
     *
     * @return
     */
    public boolean validateDataRefresh() {
        if (BusinessUtil.checkInProgressCommand(baseActivity, null, true)) {
            dismissLoadingViews();
            return false;
        }
        if (!BusinessUtil.checkDataRefreshAuth(baseActivity, Constants.ENTITLEMENT_M01DATA_REFRESH)) {
            dismissLoadingViews();
            return false;
        }
        return true;
    }

    private CarStatusPresenter getPresenter() {
        if (statusPresenter == null) {
            statusPresenter = new CarStatusPresenter(baseActivity.getScheduler(), baseActivity);
            statusPresenter.setStatusView(this);
        }
        return statusPresenter;
    }

    @Override
    public void showCarStatus(DiagnosticResponses carStatus) {
        log.d("showCarStatus...." + carStatus);
        dismissLoadingViews();
        List<DiagnosticResponse> diagnosticResponses = carStatus.getDiagnosticResponse();
        if (diagnosticResponses != null && diagnosticResponses.size() > 0) {
            checkMaintainBundle.clear();
            showPsiStatus(diagnosticResponses);         //显示胎压信息
            if (ApplicationUtil.getInstance().isPhev()) {
                showHevCarStatus(diagnosticResponses);  //显示phev车况数据
            } else {
                showFuelCarStatus(diagnosticResponses); //显示非phev车况数据
            }
            if (!checkMaintainBundle.isEmpty()) {        //设置可点击查看维修保养建议
                rbtn_checkAdvice.setBackgroundColor(getResources().getColor(R.color.carmanage_item_color));
                rbtn_checkAdvice.setEnabled(true);
            }
        }
    }

    /**
     * 显示胎压信息
     */
    private void showPsiStatus(List<DiagnosticResponse> diagnosticResponses) {
        resetPsiValue();
        for (DiagnosticResponse psiBean : diagnosticResponses) {
            if (TextUtils.equals("TIRE PRESSURE", psiBean.getName())) { //胎压
                List<DiagnosticElement> dEleBeanList = psiBean.getDiagnosticElement();
                psiView.updatePsiStatus(dEleBeanList);
                if (dEleBeanList != null && dEleBeanList.size() > 0)
                    for (DiagnosticElement dEleBean : dEleBeanList) {
                        switch (dEleBean.getName().toUpperCase()) {
                            case "TIRE PRESSURE LF":               //左前轮
                                setLFPsi(dEleBean);
                                break;
                            case "TIRE PRESSURE LR":               //左后轮
                                setLRPsi(dEleBean);
                                break;
                            case "TIRE PRESSURE RF":               //右前轮
                                setRFPsi(dEleBean);
                                break;
                            case "TIRE PRESSURE RR":               //右后轮
                                setRRPsi(dEleBean);
                                break;
                            case "TIRE PRESSURE PLACARD FRONT":    //前胎压参考值
                                tv_psiFront.setText(getResources().getString(R.string.carnamage_tire_font) + "\n" + dEleBean.getValue() + dEleBean.getUnit());
                                break;
                            case "TIRE PRESSURE PLACARD REAR":     //后胎压参考值
                                tv_psiRear.setText(getResources().getString(R.string.carmanage_tire_back) + "\n" + dEleBean.getValue() + dEleBean.getUnit());
                                break;
                        }
                    }
                break;
            }
        }
    }

    private void resetPsiValue() {
        tv_psiFront.setText(getResources().getString(R.string.carnamage_tire_font) + "\n" + "---");
        tv_psiRear.setText(getResources().getString(R.string.carmanage_tire_back) + "\n" + "---");
        tv_lfPsi.setText("---");
        tv_lrPsi.setText("---");
        tv_rfPsi.setText("---");
        tv_rrPsi.setText("---");
    }

    /**
     * 左前胎压
     *
     * @param dEleBean
     */
    private void setLFPsi(DiagnosticElement dEleBean) {
        tv_lfPsi.setText(dEleBean.getValue() + dEleBean.getUnit());
        checkMaintainBundle.putString(Constants.TIRE_PRESSURE_LF, dEleBean.getValue());
        switch (dEleBean.getMessage().toUpperCase()) {
            case "RED":
                img_lfPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_left_up_red));
                break;
            case "GREEN":
                img_lfPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_left_up_blue));
                break;
            case "YELLOW":
                img_lfPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_left_up_yellow));
                break;
        }
    }

    /**
     * 左后胎压
     *
     * @param dEleBean
     */
    private void setLRPsi(DiagnosticElement dEleBean) {
        tv_lrPsi.setText(dEleBean.getValue() + dEleBean.getUnit());
        checkMaintainBundle.putString(Constants.TIRE_PRESSURE_LR, dEleBean.getValue());
        switch (dEleBean.getMessage().toUpperCase()) {
            case "RED":
                img_lrPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_left_down_red));
                break;
            case "GREEN":
                img_lrPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_left_down_blue));
                break;
            case "YELLOW":
                img_lrPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_left_down_yellow));
                break;
        }
    }

    /**
     * 右前胎压
     *
     * @param dEleBean
     */
    private void setRFPsi(DiagnosticElement dEleBean) {
        tv_rfPsi.setText(dEleBean.getValue() + dEleBean.getUnit());
        checkMaintainBundle.putString(Constants.TIRE_PRESSURE_RF, dEleBean.getValue());
        switch (dEleBean.getMessage().toUpperCase()) {
            case "RED":
                img_rfPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_right_up_red));
                break;
            case "GREEN":
                img_rfPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_right_up_blue));
                break;
            case "YELLOW":
                img_rfPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_right_up_yellow));
                break;
        }
    }

    /**
     * 右后胎压
     *
     * @param dEleBean
     */
    private void setRRPsi(DiagnosticElement dEleBean) {
        tv_rrPsi.setText(dEleBean.getValue() + dEleBean.getUnit());
        checkMaintainBundle.putString(Constants.TIRE_PRESSURE_RR, dEleBean.getValue());
        switch (dEleBean.getMessage().toUpperCase()) {
            case "RED":
                img_rrPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_right_down_red));
                break;
            case "GREEN":
                img_rrPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_right_down_blue));
                break;
            case "YELLOW":
                img_rrPsi.setImageBitmap(BitmapUtil.readBitMap(baseActivity, R.drawable.carmanage_tire_right_down_yellow));
                break;
        }
    }

    /**
     * 显示非PHEV车辆车况信息
     */
    private void showFuelCarStatus(List<DiagnosticResponse> diagnosticResponses) {
        resetFuelCarStatus();
        for (DiagnosticResponse responseBean : diagnosticResponses) {
            switch (responseBean.getName()) {
                case "OIL LIFE":            //机油寿命
                    setOilLife(responseBean);
                    break;
                case "ODOMETER":            //总里程数
                    setOdoMeter(responseBean);
                    break;
                case "FUEL TANK INFO":      //燃油余量
                    setFuelTankInfo(responseBean);
                    break;
            }
        }
    }

    private void resetFuelCarStatus() {
        tv_fuelCarSumMiles.setText("---");
        tv_fuelCarOilLife.setText("---");
    }

    /**
     * 显示混合动力类型车辆综合信息
     */
    private void showHevCarStatus(List<DiagnosticResponse> diagnosticResponses) {
        resetHevStatus();
        for (DiagnosticResponse responseBean : diagnosticResponses) {
            switch (responseBean.getName().toUpperCase()) {
                case "EV CHARGE STATE":    //充电状态
                    setChargingStatus(responseBean);
                    break;
                case "EV BATTERY LEVEL":    //电池电量
                    setBattery(responseBean);
                    break;
                case "VEHICLE RANGE":       //剩余燃油可行使里程（包括：综合续航里程-TOTAL RANGE、电动续航里程-EV RANGE、GAS RANGE
                    setRange(responseBean);
                    break;
                case "OIL LIFE":            //机油寿命
                    setOilLife(responseBean);
                    break;
                case "FUEL TANK INFO":      //燃油余量
                    setFuelTankInfo(responseBean);
                    break;
                case "ODOMETER":            //总里程数
                    setOdoMeter(responseBean);
                    break;
            }
        }
    }

    private void resetHevStatus() {
        img_chargingSatus.setVisibility(View.GONE);
        tv_chargePercent.setVisibility(View.GONE);
        tv_chargingStatus.setText(R.string.charge_not_fetch);
        tv_battery.setText("---");
        tv_synthesizeMiles.setText("---");
        tv_elecMiles.setText("---");
        tv_oilLife.setText("---");
        tv_sumMiles.setText("---");
    }

    /**
     * 充电状态
     */
    private void setChargingStatus(DiagnosticResponse responseBean) {
        List<DiagnosticElement> chargeList = responseBean.getDiagnosticElement();
        if (chargeList != null && !chargeList.isEmpty()) {
            for (DiagnosticElement elementBean : chargeList) {
                if ("EV CHARGE STATE".equals(elementBean.getName().toUpperCase())) {
                    switch (elementBean.getValue().toLowerCase()) {
                        case "charging":
                            tv_chargePercent.setVisibility(View.VISIBLE);
                            tv_chargingStatus.setText(R.string.elec_charging);
                            img_chargingSatus.setVisibility(View.VISIBLE);
                            AnimationDrawable drawable = (AnimationDrawable) ContextCompat.getDrawable(baseActivity,R.drawable.phev);
                            img_chargingSatus.setImageDrawable(drawable);
                            drawable.start();
                            break;
                        case "not_charging":
                            tv_chargingStatus.setText(R.string.charge_not_charging);
                            break;
                        case "charging_complete":
                            tv_chargingStatus.setText(R.string.charge_full_complete);
                            break;
                        case "charging_aborted":
                            tv_chargingStatus.setText(R.string.charge_full_aborted);
                            break;
                    }
                    break;
                }
            }
        }
    }

    /**
     * 电池电量
     */
    private void setBattery(DiagnosticResponse responseBean) {
        List<DiagnosticElement> batteryList = responseBean.getDiagnosticElement();
        if (batteryList != null && !batteryList.isEmpty()) {
            DiagnosticElement batteryBean = batteryList.get(0);
            int battery = (int) Math.rint(Double.valueOf(batteryBean.getValue()));
            TextViewUtil.setText(tv_battery,
                    String.valueOf(battery),
                    String.valueOf(battery) + batteryBean.getUnit()
            );
            tv_chargePercent.setText(String.format(getString(R.string.cur_charge_percent), battery + batteryBean.getUnit()));
            checkMaintainBundle.putString(Constants.EV_BATTERY_LEVEL, batteryBean.getValue());
        }
    }

    /**
     * 续航里程(剩余燃油可行使里程)
     * 分为：综合续航里程、电动续航里程、GAS RANGE
     */
    private void setRange(DiagnosticResponse responseBean) {
        List<DiagnosticElement> totalRangeList = responseBean.getDiagnosticElement();
        if (totalRangeList != null && !totalRangeList.isEmpty()) {
            for (DiagnosticElement elementBean : totalRangeList) {
                switch (elementBean.getName().toUpperCase()) {
                    case "GAS RANGE":         //GAS RANGE
                        break;
                    case "TOTAL RANGE":       //综合续航里程-TOTAL RANGE
                        setTotalRange(elementBean);
                        break;
                    case "EV RANGE":          //电动续航里程-EV RANGE
                        setEvRange(elementBean);
                        break;
                }
            }
        }
    }

    /**
     * 综合续航里程
     */
    private void setTotalRange(DiagnosticElement totalRange) {
        TextViewUtil.setText(tv_synthesizeMiles,
                String.valueOf((int) Math.rint(Double.valueOf(totalRange.getValue()))),
                String.valueOf((int) Math.rint(Double.valueOf(totalRange.getValue()))) + totalRange.getUnit()
        );
    }

    /**
     * 电动续航里程
     */
    private void setEvRange(DiagnosticElement evRange) {
        TextViewUtil.setText(tv_elecMiles,
                String.valueOf((int) Math.rint(Double.valueOf(evRange.getValue()))),
                String.valueOf((int) Math.rint(Double.valueOf(evRange.getValue()))) + evRange.getUnit()
        );
    }

    /**
     * 机油寿命
     */
    private void setOilLife(DiagnosticResponse responseBean) {
        List<DiagnosticElement> oilList = responseBean.getDiagnosticElement();
        if (oilList != null && !oilList.isEmpty()) {
            DiagnosticElement oilBean = oilList.get(0);
            int oilLife = (int) Math.round(Double.valueOf(oilBean.getValue()));
            TextViewUtil.setText(ApplicationUtil.getInstance().isPhev() ? tv_oilLife : tv_fuelCarOilLife,
                    String.valueOf(oilLife),
                    String.valueOf(oilLife) + oilBean.getUnit()
            );
            checkMaintainBundle.putInt(Constants.OIL_LIFE, oilLife);
        }
    }

    /**
     * 燃油余量
     */
    private void setFuelTankInfo(DiagnosticResponse responseBean) {
        List<DiagnosticElement> fuelList = responseBean.getDiagnosticElement();
        if (fuelList != null && !fuelList.isEmpty()) {
            for (DiagnosticElement elementBean : fuelList) {
                if ("FUEL LEVEL".equals(elementBean.getName().toUpperCase())) {
                    if (!TextUtils.isEmpty(elementBean.getValue())) {
                        if (CommonUtil.isNumerice(elementBean.getValue())) {
                            float fuel_value = Float.valueOf(elementBean.getValue());
                            fuel_value = Math.round(fuel_value);
                            fuel_value = fuel_value <= 0 ? 0 : fuel_value;
                            if (!ApplicationUtil.getInstance().isPhev()) {   //非hev燃油余量显示
                                dialView_fuel.showByPercent(fuel_value / 100);
                                tv_remainFuelPer.setText(String.format(getResources().getString(R.string.remain_fuel), (int) fuel_value + elementBean.getUnit()));
                            } else {                                      //hev燃油余量显示
                                fuelView.playAnimator(fuel_value/100);
                            }
                            checkMaintainBundle.putInt(Constants.FUEL_TANK_INFO, (int) fuel_value);
                        }
                    }
                    break;
                }
            }
        }
    }

    /**
     * 总里程
     */
    private void setOdoMeter(DiagnosticResponse responseBean) {
        List<DiagnosticElement> odoList = responseBean.getDiagnosticElement();
        if (odoList != null && !odoList.isEmpty()) {
            DiagnosticElement odoBean = odoList.get(0);
            int totalMiles = (int) Math.round(Double.valueOf(odoBean.getValue()));
            TextViewUtil.setText(ApplicationUtil.getInstance().isPhev() ? tv_sumMiles : tv_fuelCarSumMiles,
                    String.valueOf(totalMiles),
                    String.valueOf(totalMiles) + odoBean.getUnit()
            );
            checkMaintainBundle.putInt(Constants.ODOMETER, totalMiles);
        }
    }

    /**
     * 跳转充电桩搜索页面
     */
    private void gotoChargingPile() {
        Intent it = new Intent(baseActivity, ChargingPileActivity.class);
        it.putExtra(FinalConstants.JUMP_FLAG, ChargingPileListFragment.class.getName());
        startActivity(it);
    }

    /**
     * 跳转维修保养建议页面
     */
    private void gotoCheckMaintain() {
        Intent intent = new Intent(baseActivity, CheckMaintainActivity.class);
        intent.putExtras(checkMaintainBundle);
        startActivity(intent);
    }

    /**
     * 数据库中没有缓存车况数据，点击确定则发送指令刷新数据
     */
    @Override
    public void showNoData() {
        dismissLoadingViews();
        askForRefresh();
    }

    private void askForRefresh() {
        AlertDialogUtil.showAlertDialog(baseActivity, R.string.refresh_data, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                pl_loading.setVisibility(View.VISIBLE);
                refreshVechileStatus();
            }
        }, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }

    @Override
    public void showOnErr(Throwable throwable) {
        dismissLoadingViews();
        if (throwable != null && throwable.getMessage() != null) {
            log.d("showOnErr" + throwable.getMessage());
            ToastUtil.show(baseActivity, throwable.getMessage());
        }
    }

    @Override
    public void showCompleteTime(String time) {

    }

    @Override
    public void showLoding() {}

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (statusPresenter != null) {
            statusPresenter.finish();
            statusPresenter = null;
        }
    }
}
